@page "/privacyMode"
@inherits ImportantComponentBase

<MyAppBar Title="@(I18n.T("Privacy mode"))"
          OnClick="NavigateToBack">
</MyAppBar>

@if (_isRender)
{
    <ScrollContainer>
        <MCard Class="mb-5"
               Elevation="0"
               Rounded="@("lg")">
            <MList Class="py-0">
                <MListItem>
                    <MListItemIcon>
                        <MIcon>
                            menu_open
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            <wc-auto-scroll-text>@(I18n.T("The display is set to private"))</wc-auto-scroll-text>
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            <wc-auto-scroll-text>@(I18n.T("Show the Set Private option in the diary menu"))</wc-auto-scroll-text>
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <SettingSwitch @bind-Value="showSetPrivacyDiary"
                                       SettingKey="@nameof(Setting.SetPrivacyDiary)">
                        </SettingSwitch>
                    </MListItemAction>
                </MListItem>

                <MDivider Class="mx-5"></MDivider>

                <MListItem>
                    <MListItemIcon>
                        <MIcon>
                            dark_mode
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            <wc-auto-scroll-text>@(I18n.T("Enable dark mode"))</wc-auto-scroll-text>
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            <wc-auto-scroll-text>@(I18n.T("Enable dark mode when entering privacy mode"))</wc-auto-scroll-text>
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <SettingSwitch @bind-Value="enablePrivacyModeDark"
                                       SettingKey="@nameof(Setting.PrivacyModeDark)">
                        </SettingSwitch>
                    </MListItemAction>
                </MListItem>
            </MList>
        </MCard>

        <MCard Class="mb-5"
               Elevation="0"
               Rounded="@("lg")">
            <MList Class="py-0">
                <MListItem>
                    <MListItemIcon>
                        <MIcon>
                            mdi:mdi-location-enter
                        </MIcon>
                    </MListItemIcon>

                    <MListItemContent>
                        <MListItemTitle>
                            <wc-auto-scroll-text>@(I18n.T("Hide default entry"))</wc-auto-scroll-text>
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            <wc-auto-scroll-text>
                                @(I18n.T("After hiding, it can be accessed through function search, which is located in the upper right corner of the \"Mine\" page"))
                            </wc-auto-scroll-text>
                        </MListItemSubtitle>
                    </MListItemContent>

                    <MListItemAction>
                        <MSwitch @bind-Value="hidePrivacyModeEntrance"
                                 TValue="bool"
                                 Readonly="true"
                                 OnClick="SwitchHidePrivacyModeEntrance"
                                 Dense="true"
                                 Inset="true"
                                 Color="@MasaBlazor.Theme.CurrentTheme.OnSurface">
                        </MSwitch>
                    </MListItemAction>
                </MListItem>

                <MDivider Class="mx-5"></MDivider>

                @if (hidePrivacyModeEntrance)
                {
                    <MListItem OnClick="() => showPrivacyModeFunctionSearchKeyDialog = true">
                        <MListItemIcon>
                            <MIcon>
                                keyboard
                            </MIcon>
                        </MListItemIcon>

                        <MListItemContent Style="flex-basis:50%;">
                            <MListItemTitle>
                                <wc-auto-scroll-text>@(I18n.T("Custom search keywords"))</wc-auto-scroll-text>
                            </MListItemTitle>
                            <MListItemSubtitle Class="text-caption-xs-only">
                                <wc-auto-scroll-text>@(I18n.T("Enter keywords in the feature search to display privacy mode"))</wc-auto-scroll-text>
                            </MListItemSubtitle>
                        </MListItemContent>

                        <MListItemContent Class="ml-2" Style="flex-basis:50%;">
                            <MListItemSubtitle Class="font-weight-bold">
                                <wc-auto-scroll-text class="justify-end">@privacyModeFunctionSearchKey</wc-auto-scroll-text>
                            </MListItemSubtitle>
                        </MListItemContent>

                        <MListItemAction>
                            <MIcon>chevron_right</MIcon>
                        </MListItemAction>
                    </MListItem>
                }
                else
                {
                    <MListItem OnClick="() => showPrivacyModeEntrancePasswordDialog = true">
                        <MListItemIcon>
                            <MIcon>
                                key
                            </MIcon>
                        </MListItemIcon>

                        <MListItemContent Style="flex-basis:50%;">
                            <wc-auto-scroll-text>@(I18n.T("Set default entry password"))</wc-auto-scroll-text>
                        </MListItemContent>

                        <MListItemContent Class="ml-2" Style="flex-basis:50%;">
                            <MListItemSubtitle>
                                <wc-auto-scroll-text class="justify-end">@PrivacyModeEntrancePasswordSetStateText</wc-auto-scroll-text>
                            </MListItemSubtitle>
                        </MListItemContent>

                        <MListItemAction>
                            <MIcon>chevron_right</MIcon>
                        </MListItemAction>
                    </MListItem>
                }
            </MList>
        </MCard>

        @if (Desktop)
        {
            <MCard Class="mb-5"
                   Elevation="0"
                   Rounded="@("lg")">
                <MList Class="py-0">
                    <MListItem OnClick="SwitchPrivacyMode">
                        <MListItemIcon>
                            <MIcon>
                                swap_horiz
                            </MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <wc-auto-scroll-text>@(I18n.T(SwitchPrivacyModeText))</wc-auto-scroll-text>
                        </MListItemContent>
                        <MListItemAction>
                            <MIcon>chevron_right</MIcon>
                        </MListItemAction>
                    </MListItem>
                </MList>
            </MCard>
        }

        <MCard Class="mb-5"
               Elevation="0"
               Rounded="@("lg")">
            <MList Class="py-0">
                <MListItem OnClick="MoveOldPrivacyDiaries">
                    <MListItemIcon>
                        <MIcon>
                            mdi:mdi-file-move-outline
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            <wc-auto-scroll-text>@(I18n.T("Move the old version of Privacy Diary"))</wc-auto-scroll-text>
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            <wc-auto-scroll-text>@(I18n.T("Move the data from the old version of the privacy diary to the new version"))</wc-auto-scroll-text>
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <MIcon>chevron_right</MIcon>
                    </MListItemAction>
                </MListItem>
            </MList>
        </MCard>

        <MAlert Class="mb-5 text-subtitle-2 text--secondary text-pre-wrap"
                Elevation="0"
                Rounded="@("lg")"
                Icon="@("info")">
            @(I18n.T("Privacy mode data from version 1.3.9 and earlier will be automatically migrated to the new version of privacy mode after the update. \nIf the old privacy data is obtained by restoring backups or importing, it will be displayed together with the regular diary. Please click the migration button above to move them to privacy mode."))
        </MAlert>
    </ScrollContainer>

    @if (Mobile)
    {
        <div class="pa-3">
            <MButton Class="inverse-surface mb-2"
                     Rounded="true"
                     Block="true"
                     Large="true"
                     OnClick="SwitchPrivacyMode">
                @(I18n.T(SwitchPrivacyModeText))
            </MButton>
        </div>
    }

    <InputDialog @bind-Visible="showPrivacyModeFunctionSearchKeyDialog"
                 Text="@privacyModeFunctionSearchKey"
                 Title="@(I18n.T("Custom search keywords"))"
                 Placeholder="@(I18n.T("Please enter keywords"))"
                 OnOK="SavePrivacyModeSearchKey">
    </InputDialog>

    <PasswordDialog @bind-Visible="showPrivacyModeEntrancePasswordDialog"
                    Title="@(I18n.T("Set default entry password"))"
                    MaxLength="20"
                    OnOK="SetPassword"
                    OnReset="ResetPassword">
    </PasswordDialog>

    <CustomMDialog @bind-MyValue="showHidePrivacyModeEntranceConfirmDialog"
                   ContentClass="rounded-lg"
                   MaxWidth="420">
        <MCard>
            <MCardTitle Class="font-weight-bold flex-nowrap">
                <wc-auto-scroll-text>@(I18n.T("Hide default entry"))</wc-auto-scroll-text>
                <MSpacer></MSpacer>
                <MButton Icon="true"
                         OnClick="@(() => showHidePrivacyModeEntranceConfirmDialog = false)">
                    <MIcon>close</MIcon>
                </MButton>
            </MCardTitle>
            <MCardText Class="pb-0">
                <div>
                    @(I18n.T("After hiding, it can be accessed through function search, which is located in the upper right corner of the \"Mine\" page"))
                </div>
                <div>
                    @(I18n.T("Enter keywords in the feature search to display privacy mode"))
                </div>
                <div class="d-flex align-end">
                    @(I18n.T("Current key"))
                    <div class="font-weight-bold text-h6 ml-2">@privacyModeFunctionSearchKey</div>
                </div>
            </MCardText>
            <MCardActions>
                <MSpacer></MSpacer>
                <MButton Text
                         OnClick="() => showHidePrivacyModeEntranceConfirmDialog = false">
                    @(I18n.T("Cancel"))
                </MButton>
                <MButton Text
                         Color="primary"
                         OnClick="ConfirmHidePrivacyModeEntrance">
                    @(I18n.T("OK"))
                </MButton>
            </MCardActions>
        </MCard>
    </CustomMDialog>
}
